<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>后台管理员</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">房间ID</label>
                    <div class="layui-input-block">
                        <input type="text" name="roomid" id="roomid" placeholder="请输入" required
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn" lay-submit lay-filter="search" id="search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn" lay-submit id="reset">
                        重置
                    </button>
                </div>
            </div>

        </div>
        <div class="layui-card-body">
            <table id="demo" class="layui-hide" lay-filter="test"></table>
        </div>
    </div>
</div>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>进入</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i
            class="layui-icon layui-icon-delete"></i>删除</a>
</script>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-danger " lay-event="delAll">批量删除</button>
    </div>
</script>

<script src="/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['laydate', 'layer', 'table','carousel'], function () {
        var $ = layui.$,
            form = layui.form,
            laydate = layui.laydate,
            table = layui.table,
            carousel = layui.carousel,
            layer = layui.layer;

        //监听搜索
        $('#search').on('click', function() {
            var roomid = $('#roomid');
            if (roomid.val() != '') {
                table.reload('idTest', {
                    url : '/getRoomById',
                    page : {
                        curr : 1
                    },
                    where : {
                        roomid : roomid.val(),
                    }
                });
            } else {
                layer.msg('请输入房间号', {
                    icon: 2,
                    time: 1500
                });
            }
        });
        //数据重置
        $('#reset').on('click', function() {
            $('#roomid').val('');
            table.reload('idTest', {
                url : '/getWebRoomList',
                page : {
                    curr : 1
                }
            });
        });

        //表格初始化
        table.render({
            elem: '#demo',
            id: 'idTest',
            url: '/getWebRoomList',
            page: true,
            toolbar: '#toolbarDemo',
            height: 'full-130',
            cols: [
                [
                    {type: 'checkbox', fixed: 'left'},
                    {
                        field: 'id',
                        title: 'ID',
                        width: 160,
                        sort: true
                    }, {
                    field: 'name',
                    title: '房间名（也是会议名）',
                    width: 270
                },{
                    field: 'id',
                    title: '房间地址',
                    width: 300,
                    // templet:'<div>http://localhost:8080/rtmp/{{ d.id }}</div>'
                    templet:'<div>https://www.cyansg.top/webrtc/{{ d.id }}</div>'
                },{
                    fixed:'right',title: '操作', toolbar: '#barDemo', width: 160
                }]
            ]
        });
        //监听头工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id)
                , checkData = checkStatus.data,
                formData = [];
            switch (obj.event) {
                case 'delAll':
                    if (checkData.length == 0) {
                        layer.msg("不能为空");
                    } else {
                        layer.confirm('是否删除此记录?', {icon: 3, title: '提示'}, function (index) {
                            for (var i = 0; i < checkData.length; i++) {
                                formData.push(checkData[i].id);
                            }
                            $.ajax({
                                type: "delete",
                                contentType: 'application/json',
                                url: "/delRoom/" + formData,
                                data: {},
                                dataType: 'json',
                                success: function (data) {
                                    if (data.code == 200) {
                                        layer.msg('删除成功',
                                            {
                                                icon: 1,
                                                time: 1000
                                            }, function () {
                                                layer.close(index); //关闭弹层
                                                window.location.reload();
                                            });
                                    } else {
                                        layer.msg("后台出错");
                                    }
                                }
                            });
                        });
                    }
                    break;
            }
            ;
        });
        //监听工具条
        //监听事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            switch (obj.event) {
                case 'edit':
                    window.open("https://www.cyansg.top/webrtc/"+data.id,"_blank");
                    break;
                case 'del':
                    layer.confirm('是否删除此记录?', {icon: 3, title: '提示'}, function (index) {
                        $.ajax({
                            type: "delete",
                            contentType: 'application/json',
                            url: "/delRoom/" + data.id,
                            data: {},
                            dataType: 'json',
                            success: function (data) {
                                if (data.code == 200) {
                                    layer.msg('删除成功',
                                        {
                                            icon: 1,
                                            time: 1000
                                        }, function () {
                                            layer.close(index); //关闭弹层
                                            window.location.reload();
                                        });
                                } else {
                                    layer.msg("后台出错");
                                }
                            }
                        });
                    });
                    break;
            }
            ;
        });
    });
</script>
</body>
</html>
